package com.cskaoyan.gateway.controller.cashier;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.pay.PayService;
import com.mall.pay.constrant.PayRetCode;
import com.mall.pay.dto.PayRequest;
import com.mall.pay.dto.PayResponse;
import com.mall.pay.dto.QueryStatusRequest;
import com.mall.pay.dto.QueryStatusResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lichao
 * @createdate 2021-01-27 22:04
 */
@RestController
@RequestMapping("cashier")
public class CashierController {

    @Reference(check = false,retries = 0,timeout = 80000)
    PayService payService;

    @PostMapping("pay")
    public ResponseData pay(@RequestBody PayRequest request){
        System.out.println(request);
        PayResponse response = payService.pay(request);

        return response.getCode().equals("200") ?  new ResponseUtil<String>().setData(response.getCodeUrl()):
                                 new ResponseUtil<String>().setData(response.getMsg());
    }

    @GetMapping("/queryStatus")
    public ResponseData queryStatus(@RequestParam String orderId){
        QueryStatusRequest request = new QueryStatusRequest();

        request.setOrderId(orderId);

        QueryStatusResponse response = payService.queryStatus(request);

        if(response.getPayRetCode().equals(PayRetCode.SUCCESS)){
            return new ResponseUtil<>().setData(null);
        }
        return new ResponseUtil<>().setErrorMsg("fail");


    }


}
